home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / v cisle / htttrack / httrack-3.41-3.exe / {app} / libtest / callbacks-example-changecontent.c < prev    next >
C/C++ Source or Header  |  2006-06-04  |  2KB  |  63 lines

  1. /*
  2.     HTTrack external callbacks example : display all incoming request headers
  3.     Example of <wrappername>_init and <wrappername>_exit call (httrack >> 3.31)
  4.     .c file
  5.  
  6.     How to build: (callback.so or callback.dll)
  7.       With GNU-GCC:
  8.         gcc -O -g3 -Wall -D_REENTRANT -shared -o mycallback.so callbacks-example.c -lhttrack1
  9.       With MS-Visual C++:
  10.         cl -LD -nologo -W3 -Zi -Zp4 -DWIN32 -Fe"mycallback.dll" callbacks-example.c libhttrack1.lib
  11.  
  12.       Note: the httrack library linker option is only necessary when using libhttrack's functions inside the callback
  13.  
  14.     How to use:
  15.       httrack --wrapper mycallback ..
  16. */
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21.  
  22. /* Standard httrack module includes */
  23. #include "httrack-library.h"
  24. #include "htsopt.h"
  25. #include "htsdefines.h"
  26.  
  27. /* Local function definitions */
  28. static int postprocess(t_hts_callbackarg *carg, httrackp *opt, 
  29.                        char** html, int* len,
  30.                        const char* url_address, const char* url_file);
  31.  
  32. /* 
  33. module entry point 
  34. */
  35. EXTERNAL_FUNCTION int hts_plug(httrackp *opt, const char* argv) {
  36.   const char *arg = strchr(argv, ',');
  37.   if (arg != NULL)
  38.     arg++;
  39.  
  40.   /* Plug callback functions */
  41.   CHAIN_FUNCTION(opt, postprocess, postprocess, NULL);
  42.  
  43.   return 1;  /* success */
  44. }
  45.  
  46. static int postprocess(t_hts_callbackarg *carg, httrackp *opt, char** html,int* len,const char* url_address,const char* url_file) {
  47.   char *old = *html;
  48.  
  49.   /* Call parent functions if multiple callbacks are chained. */
  50.   if (CALLBACKARG_PREV_FUN(carg, postprocess) != NULL) {
  51.     if (CALLBACKARG_PREV_FUN(carg, postprocess)(CALLBACKARG_PREV_CARG(carg), opt, html, len, url_address, url_file)) {
  52.       /* Modified *html */
  53.       old = *html;
  54.     }
  55.   }
  56.  
  57.   /* Process */
  58.   *html = strdup(*html);
  59.   hts_free(old);
  60.  
  61.   return 1;
  62. }
  63.